﻿using System.Windows.Input;
using ClientOverflow.DataTransferObjects;
using ClientOverflow.ViewModels.Interfaces;
using ClientOverflow.ViewModels.MainMenus;

namespace ClientOverflow.ViewModels.QuestionsListViewModels
{
    /// <summary>
    /// AnswerViewModel is a view-model that wraps a single answer as its model. The view-model is used
    /// in a list context where every answer expose its question title and a command that allows navigation
    /// to the single question view where the details of the question and its answers are shown.
    /// </summary>
    internal class AnswerViewModel : IAnswerInListViewModel
    {
        public static IAnswerInListViewModel CreateAnswerViewModel(Answer answer, IMenusViewModel viewModel)
        {
            return new AnswerViewModel(answer, viewModel);
        }

        private readonly Question question;

        private AnswerViewModel(Answer answer, IMenusViewModel viewModel)
        {
            question = answer.Question;
            ShowQuestionCommand = new ShowQuestionCommand(answer.Question, viewModel);
        }

        public string Title
        {
            get { return question.Title; }
        }

        public ICommand ShowQuestionCommand { get; private set; }
    }
}